# app/map_planner/models/base_model.py
from datetime import datetime, timezone
from typing import Optional

from sqlalchemy import Integer, String, DateTime
from sqlalchemy.orm import Mapped, mapped_column

from app.core import DeclarativeBase


class Warehouse1(DeclarativeBase):
    """库位信息表1"""
    __tablename__ = 'warehouse_1'
    
    id: Mapped[int] = mapped_column(Integer, primary_key=True)  # 库位id号
    location: Mapped[str] = mapped_column(String(50), nullable=False)  # 库位坐标号，格式："wh,x,y" <-> "库区,层,列"
    status: Mapped[int] = mapped_column(Integer, default=0)  # 库位状态
    pallet_id: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)  # 托盘号，可为空
    update_time: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        default=lambda: datetime.now(timezone.utc),
        onupdate=lambda: datetime.now(timezone.utc)
    )  # 更新时间，使用UTC时间

    def __repr__(self):
        return f"<Warehouse1(id={self.id}, location={self.location}, status={self.status}, pallet_id={self.pallet_id})>"


class Warehouse2(DeclarativeBase):
    """库位信息表2"""
    __tablename__ = 'warehouse_2'
    
    id: Mapped[int] = mapped_column(Integer, primary_key=True)  # 库位id号
    location: Mapped[str] = mapped_column(String(50), nullable=False)  # 库位坐标号，格式："wh,x,y" <-> "库区,层,列"
    status: Mapped[int] = mapped_column(Integer, default=0)  # 库位状态
    pallet_id: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)  # 托盘号，可为空
    update_time: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        default=lambda: datetime.now(timezone.utc),
        onupdate=lambda: datetime.now(timezone.utc)
    )  # 更新时间，使用UTC时间

    def __repr__(self):
        return f"<Warehouse2(id={self.id}, location={self.location}, status={self.status}, pallet_id={self.pallet_id})>"